/*
 * Copyright (c) 2016. jiiiiiin 15398699939@163.com
 */

package com.bankscene.screenfit.vus;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.bankscene.screenfit.R;
import com.bankscene.screenfit.adapters.ViewPagerAdapter;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhaojin on 6/22/16.
 */
public class MenusTabsVu extends MenusVu {

    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewpager)
    ViewPager viewpager;

    @Override
    public void init(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable EventBus bus) {
        this.bus = bus;
        rootView = inflater.inflate(R.layout.simple_tabs_activity, container, false);
        unbinder = ButterKnife.bind(this, rootView);
        if (navView != null) {
            setupDrawerContent(navView);
        }

        tabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewpager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    public void setViewPagerAdapter(@NonNull ViewPagerAdapter viewPagerAdapter) {
        viewpager.setAdapter(viewPagerAdapter);
        tabs.setupWithViewPager(viewpager);//!Caused by: java.lang.IllegalArgumentException: ViewPager does not have a PagerAdapter set
    }
}
